// csharp
using System.Collections.Generic;
using System.Linq;

namespace CSharpPro._1030;

public class UserServiceImpl : UserService
{
    private readonly List<User> _users = new();

    public void Create(User user)
    {
        _users.Add(user);
    }

    public bool Delete(int id)
    {
        var u = _users.FirstOrDefault(x => x.Id == id);
        if (u is null) return false;
        _users.Remove(u);
        return true;
    }

    public bool Update(User user)
    {
        var idx = _users.FindIndex(x => x.Id == user.Id);
        if (idx == -1) return false;
        _users[idx] = user;
        return true;
    }

    public User? Get(int id) => _users.FirstOrDefault(x => x.Id == id);
}